<?php
/**
 * Created by PhpStorm.
 * User: asdf
 * Date: 2021/9/22
 * Time: 1:04
 */

namespace Extentions\redis;

use core\lib\Config;
use function core\p;

class Redis //命名空间(文件夹路径) + 类名 可被找到
{
    private static $instance = null;
    private $redis = null;
    private $conf = null;

    private function __construct()
    {
        $this->conf = Config::all("redis");
        $this->connect($this->conf["host"],$this->conf["port"],$this->conf["timeout"],"");
    }

    public static function Newinstance(){
        if(!self::$instance instanceof self){
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function connect($host,$port,$timeout,$passwd){
        try{
            $this->redis = new \Redis();
            $this->redis->connect($host, $port,$timeout);
        }catch (\ErrorException $e){
            p($e->getMessage()."#".
                $e->getCode()."#".
                $e->getFile()."#".
                $e->getLine());
        }
    }

}